﻿using AutoMan.Dtos;
using AutoMan.Pages.Componets;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Navigation;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraTab;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using DevExpress.Utils.CodedUISupport;
using AutoMan.Helper;
using AutoMan.Pages.Componets;

namespace AutoMan
{

    public partial class Main : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm
    {
        private TabPageHelper tabPageHelper;
        public Main()
        {
            InitializeComponent();
            tabPageHelper = new TabPageHelper(xtraTabControl1);
            #region 事件绑定
            accordionControl1.ElementClick += accordionControl1_ElementClick;
            accordionControl1.CustomDrawElement += accordionControl1_CustomDrawElement;
            xtraTabControl1.CloseButtonClick += xtraTabControl1_CloseButtonClick;
            #endregion

            #region 设置tabcontrol
            //设置显示关闭按钮
            xtraTabControl1.ClosePageButtonShowMode = DevExpress.XtraTab.ClosePageButtonShowMode.InActiveTabPageHeader;
            //首页不显示关闭按钮
            xtraTabPage1.ShowCloseButton = DevExpress.Utils.DefaultBoolean.False;
            #endregion
        }
        private void xtraTabControl1_CloseButtonClick(object? sender, EventArgs e)
        {
            DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs EArg = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;
            string name = EArg.Page.Text;//得到关闭的选项卡的text
            foreach (XtraTabPage page in xtraTabControl1.TabPages)//遍历得到和关闭的选项卡一样的Text
            {
                if (page.Text == name)
                {
                    xtraTabControl1.TabPages.Remove(page);
                    elementName.Remove(name);
                    page.Dispose();
                    accordionControl1.Refresh();
                    return;
                }
            }
        }
        #region 设置菜单选中样式
        private List<string> elementName = new List<string> { "系统首页" };
        private Color color = new Color();
        private void accordionControl1_CustomDrawElement(object sender, CustomDrawElementEventArgs e)
        {
            if (e.Element.Text == elementName[elementName.Count - 1])
            {
                e.Appearance.BackColor = Color.CornflowerBlue;
            }
            else
            {
                e.Appearance.BackColor = color;
            }
        }

        private void accordionControl1_ElementClick(object sender, ElementClickEventArgs e)
        {
            elementName.Add(e.Element.Text);
            accordionControl1.Refresh();
        }
        #endregion

        private void accordionControlElement4_Click(object sender, EventArgs e)
        {
            tabPageHelper.LoadPage(new ViewPage("FormFieldModel", "FormModel", new QueryDto() { WhereString = "表单编号=@treelistActive", Parameters = new { treelistActive = 1 } }), accordionControlElement4.Text);
        }

        private void accordionControlElement3_Click(object sender, EventArgs e)
        {
            tabPageHelper.LoadPage(new ViewPage("FormModel"), accordionControlElement3.Text);
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void accordionControlElement5_Click(object sender, EventArgs e)
        {
            tabPageHelper.LoadPage(new ViewPage("TestModel"), accordionControlElement5.Text);
        }
    }
}
